package org.zn.quality.handler;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;
import org.zn.etl.config.Constant;
import org.zn.etl.misc.CompareUtils;
import org.zn.quality.entity.QualityStrategyEntity;

@Component("TotalCompareHandler")
public class TotalCompareHandler   implements QualityHandler<Map<String, Object>, Map<String, Object>>{
	
	private static final  String KEY="total";

	@Override
	public Map<String, Object> doHandler(List<Map<String, Object>> srcData, List<Map<String, Object>> tagData,
			QualityStrategyEntity strategy) {
		// TODO Auto-generated method stub
		Map<String, Object> inspectResult =new HashMap<>();
		
			Object stotal=0;
			Object ttotal=0;
			
			if(CollectionUtils.isNotEmpty(srcData)) {
				stotal= srcData.get(0).get(KEY);
				if(stotal==null) {
					stotal=srcData.get(0).values().stream().findAny().get();
				}
			}
			
			if(CollectionUtils.isNotEmpty(tagData)) {
			ttotal=tagData.get(0).get(KEY);
			if(ttotal==null) {
				ttotal=tagData.get(0).values().stream().findAny().get();
				}
			}
				
			inspectResult.put("srcTotal", stotal);
			inspectResult.put("tagTotal", ttotal);
			inspectResult.put(Constant.DIFF_SIZE,    CompareUtils.valueEquals(stotal, ttotal)?0:1);
		 
		return inspectResult;
	}

}
